﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XNADota.GamePlay.Ability;

namespace XNADota.GamePlay
{
    public class ItemObject : BasicObject
    {
        // ability
        public List<AbilityObject> AbilityObjects;
        public bool Droppable;
        public bool Sellable;
        public bool Pawnable;

        public bool DropAfterDeath;

        public int GoldCost;

        // Art
        public string ModelFileName;
        public int ButtonPos0;
        public int ButtonPos1;
        public string InterfaceIcon;

        // Tips
        public string Description;
        public string HotKey;
        public string Name;
        public string ToolTip_Basic;
        public string ToolTip_Extended;

        public void ApplyControlPanel(ControlPanel controlPanel, int i)
        {
            controlPanel.SetArt(InterfaceIcon, InterfaceIcon, i / 4, i % 4);
        }

        public void ApplyControlPanel(ControlPanel controlPanel)
        {
            controlPanel.SetArt(InterfaceIcon, InterfaceIcon, ButtonPos0, ButtonPos1);
        }

        public ItemObject(string Id)
            : base(Id, EObjectType.ItemData)
        {

            if (Id == "I01E")
            {
                InterfaceIcon = "BTNSelectHeroOn.tga";
                return;
            }

            ObjectsManager manager = GameplayWorld.Instance.ObjectsManager;

            AbilityObjects = new List<AbilityObject>();
            Droppable = this.GetBool(manager.GetFiledValue(EObjectType.ItemData, Id, "droppable"));
            Sellable = this.GetBool(manager.GetFiledValue(EObjectType.ItemData, Id, "sellable"));
            Pawnable = this.GetBool(manager.GetFiledValue(EObjectType.ItemData, Id, "pawnable"));

            DropAfterDeath = this.GetBool(manager.GetFiledValue(EObjectType.ItemData, Id, "drop"));

            GoldCost = this.GetInt(manager.GetFiledValue(EObjectType.ItemData, Id, "goldcost"));

            ModelFileName = manager.GetFiledValue(EObjectType.ItemData, Id, "file");
            string pos = manager.GetFiledValue(EObjectType.ItemData, Id, "Buttonpos");
            if (String.IsNullOrEmpty(pos) == false)
            {
                string[] p = pos.Split(new char[] { ',' });
                if (p.Length >= 1) ButtonPos0 = this.GetInt(p[0]);
                if (p.Length >= 2) ButtonPos1 = this.GetInt(p[1]);
            }

            InterfaceIcon = manager.GetFiledValue(EObjectType.ItemData, Id, "Art");

            Description = manager.GetFiledValue(EObjectType.ItemData, Id, "description");
            HotKey = manager.GetFiledValue(EObjectType.ItemData, Id, "Hotkey");
            Name = manager.GetFiledValue(EObjectType.ItemData, Id, "Name");
            ToolTip_Basic = manager.GetFiledValue(EObjectType.ItemData, Id, "Tip");
            ToolTip_Extended = manager.GetFiledValue(EObjectType.ItemData, Id, "Ubertip");
        }
    }
}
